//
//  PKPlayMainViewController.m
//  PianKe
//
//  Created by lanou on 15/10/7.
//  Copyright (c) 2015年 李伟伟. All rights reserved.
//

#import "PKPlayMainViewController.h"
#import <UIImageView+WebCache.h>
#import "PKPlayerManager.h"
@interface PKPlayMainViewController ()

@end

@implementation PKPlayMainViewController

-(void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"configureNumber" object:nil];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _configureModel = self.dataSourceArray[self.index];
    
    _musicImageView = [[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WITDTH/2-100, 100, 200, 200)];
    [_musicImageView sd_setImageWithURL:[NSURL URLWithString:_configureModel.coverimg]];
    
    
    _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 320, SCREEN_WITDTH, 20)];
    _titleLabel.textAlignment = NSTextAlignmentCenter;
   
    
    _conmmentButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _conmmentButton.frame = CGRectMake(80, 400, 20, 20);
    [_conmmentButton setBackgroundImage:[UIImage imageNamed:@"评论按钮"] forState:UIControlStateNormal];
    
    _commentLabel = [[UILabel alloc]initWithFrame:CGRectMake(100, 400, 50, 20)];
    _commentLabel.text = @"";
    
    _likeButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _likeButton.frame = CGRectMake(250, 400, 20, 20);
    [_likeButton setBackgroundImage:[UIImage imageNamed:@"喜欢"] forState:UIControlStateNormal];
    
    _likeLabel = [[UILabel alloc]initWithFrame:CGRectMake(270, 400, 50, 20)];
    _likeLabel.text = @"";
    
    UIButton *downloadButton = [UIButton buttonWithType:UIButtonTypeCustom];
    downloadButton.frame = CGRectMake(30, 460, 30, 30);
    [downloadButton setBackgroundImage:[UIImage imageNamed:@"下载"] forState:UIControlStateNormal];
    
    _slider = [[UISlider alloc]initWithFrame:CGRectMake(70, 460, 200, 30)];

    _timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(280, 460, 60, 30)];
    _timeLabel.text = @"0";
    
    [self.view addSubview:_musicImageView];
    [self.view addSubview:_titleLabel];
    [self.view addSubview:_conmmentButton];
    [self.view addSubview:_commentLabel];
    [self.view addSubview:_likeButton];
    [self.view addSubview:_likeLabel];
    [self.view addSubview:downloadButton];
    [self.view addSubview:_slider];
    [self.view addSubview:_timeLabel];
    
    
    [self setConfigureModel:_configureModel];
        
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(configureLabelNumber:) name:@"configureNumber" object:nil];
    
    
    [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(changeValue) userInfo:nil repeats:YES];
    
//    NSTimer *time = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(changeValue) userInfo:nil repeats:YES];
//    [[NSRunLoop currentRunLoop]addTimer:time forMode:NSRunLoopCommonModes];
    
    
    
    
}

static NSInteger i = 0;
-(void)changeValue
{
    PKPlayerManager *manager = [PKPlayerManager sharedManager];
    _slider.value = (CGFloat)[manager currentTime]/(CGFloat)[manager totalTime];
   
    _timeLabel.text =[NSString stringWithFormat:@"%ld",i];
    i++;
    
}

-(void)setConfigureModel:(PKRadioDetailModel *)configureModel
{
    _configureModel = configureModel;
     _titleLabel.text = _configureModel.title;
    [_musicImageView sd_setImageWithURL:[NSURL URLWithString:_configureModel.coverimg]];
}

-(void)configureLabelNumber:(NSNotification *)model;
{
    _likeLabel.text = [NSString stringWithFormat:@"%@", model.userInfo[@"like"]];

    _commentLabel.text = [NSString stringWithFormat:@"%@", model.userInfo[@"comment"]];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
